    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package miage.ecom.commandes;

import java.io.PrintStream;
import java.util.StringTokenizer;
import miage.ecom.Main.Shell;
import miage.ecom.Shell.ShellContext;
import miage.ecom.exceptions.BadFormateException;
import miage.ecom.exceptions.IllegalAttributeException;

    /**
    *
    * @author User
    */
    public class OutputCommandImpl implements ShellCommand
    {
    private ShellContext _context = null;
    public OutputCommandImpl(ShellContext context)
    {
    _context = context;
    }
    /**
    * renvoie le nom de la commande
    * @return
    */
    @Override
    public String getName()
    {
    String langue = (String) _context.getVar(Shell.LANGUAGE);
    if(langue.equals("fr")) {
    
    return "sortie";}
    if(langue.equals("es")) {
    return "salida";}
    if(langue.equals("it")) {
    return "produzione";}
    else{
    //default anglais
    return "output";
    }
    }
    /**
    * renvoie le nom de la commande
    * @return
    */
    @Override
    public String getUsage()
    {
    String langue = (String) _context.getVar(Shell.LANGUAGE);
    if(langue.equals("fr")) { 
    
    return "sortie HTML|XML|TEXT|JSON";}
    if(langue.equals("es")) {
    return "salida HTML|XML|TEXT|JSON";}
    if(langue.equals("it")) {
    return "produzione HTML|XML|TEXT|JSON";}
    else{
    //default anglais
    return "output HTML|XML|TEXT|JSON";
    }
    }
    
    /**
    * renvoie la description de la commande
    * @return
    */
    @Override
    public String getShortDescription()
    {
    String langue = (String) _context.getVar(Shell.LANGUAGE);
    if(langue.equals("fr")) { 
    
    return "positionne le format de sortie.";}
    if(langue.equals("es")) {
    return "posiziona il formato di output.";}
    if(langue.equals("it")) {
    return "produzione";}
    else{
    //default anglais
    return "set the output format.";
    }
    }
    /**
    * execute la commande
    * @return
    */
    @Override
    public void execute(String cmdline, PrintStream out, PrintStream err) throws Exception
    {
    StringTokenizer st = new StringTokenizer(cmdline, " ");
    // Ignore cmd
    st.nextToken();
    if(st.countTokens()==1){
    String output = st.nextToken();
    if(("HTML".equals(output))||("XML".equals(output))||("TEXT".equals(output))||("JSON".equals(output))){
    Shell.setOutput(output);
    }else{
    throw new IllegalAttributeException();
    }
    }else{
    throw new BadFormateException();
    }
    }
    } 